package com.iwdm.renovation.ui.cart;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.iwdm.renovation.databinding.FragmentCartBinding;

public class CartFragment extends Fragment {
    FragmentCartBinding binding;
    RadioButton all;
    TextView textView;

    public CartFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        binding = FragmentCartBinding.inflate(inflater, container, false);
        RecyclerView list = binding.list;
        all = binding.all;
        textView = binding.text;
        list.setLayoutManager(new LinearLayoutManager(binding.getRoot().getContext()));
        MyCartRecyclerViewAdapter myCartRecyclerViewAdapter = new MyCartRecyclerViewAdapter();
        list.setAdapter(myCartRecyclerViewAdapter);


        all.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("全选".equals(all.getText().toString())) {
                    all.setChecked(true);
                    all.setText("取消全选");
                }else {
                    all.setChecked(false);
                    all.setText("全选");
                }

                myCartRecyclerViewAdapter.setAllChecked(all.isChecked());
                textView.setText("合计：" + myCartRecyclerViewAdapter.getItemCount() * 1599);
            }
        });
        return binding.getRoot();
    }
}
